package offer;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;

public class offerII_0056 {
    public boolean findTarget(TreeNode root, int k) {
        Set<Integer> set=new HashSet<>();
        boolean[] flag=new boolean[1];
        flag[0]=false;
        search(root,set,k,flag);
        return flag[0];
    }
    public void search(TreeNode node,Set<Integer> set,int k,boolean[] flag){
        if(node==null||flag[0]==true) return;
        search(node.left,set,k,flag);
        if(set.contains(k-node.val)){
            flag[0]=true;
            return;
        }
        set.add(node.val);
        search(node.right,set,k,flag);
    }
}
